package cn.edu.csust.cvs.management.controller;

import cn.edu.csust.cvs.management.common.ApiPageResult;
import cn.edu.csust.cvs.management.common.ApiResponse;
import cn.edu.csust.cvs.management.controller.request.RecordDeleteRequest;
import cn.edu.csust.cvs.management.controller.request.RecordPageQueryRequest;
import cn.edu.csust.cvs.management.repository.entity.RecordEntity;
import cn.edu.csust.cvs.management.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @Auther: snail
 * @Date: 2021/1/22 00:30
 * @Description: 录音管理控制器
 */
@RestController
@RequestMapping("/cvsm/record")
@Api(tags = "录音管理")
public class RecordController {

    @Autowired
    RecordService recordService;

    @ApiOperation(value = "上传录音文件", notes = "上传录音文件")
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ApiResponse upload(@RequestParam(value = "multipartFile") MultipartFile multipartFile) {

        return recordService.upload(multipartFile);
    }

    @ApiOperation(value = "录音记录分页查询", notes = "录音记录分页查询")
    @GetMapping("")
    public ApiPageResult<List<RecordEntity>> pageQuery(@Valid RecordPageQueryRequest request, BindingResult result) {

        return recordService.pageQuery(request);
    }

    @ApiOperation(value = "录音文件删除", notes = "录音文件删除")
    @DeleteMapping("")
    public ApiResponse delete(@Valid @RequestBody RecordDeleteRequest request, BindingResult result) {

        return recordService.delete(request);
    }

    @ApiOperation(value = "录音文件重命名", notes = "录音文件重命名")
    @PutMapping("/{id}")
    public ApiResponse rename(@PathVariable("id")Integer id,@Param("name")String name) {

        return recordService.rename(id,name);
    }

}
